let arr = [2, 1, 3, "3", [1, 2], 7, [4, 5, [8]], 6, [4]]
let res = [1, 2, 3, 4, 5, 6, 7, 8]
// flat 去重 排序
function flat(arr) {
    return arr.reduce((pre, curr) => {
        return pre.concat(Array.isArray(curr) ? flat(curr) : curr)
    }, [])
}

function unique(arr) {
    // return Array.from(new Set(arr))
    let map = new Map()
    arr.forEach(res => {
        map.set(String(res), res)
    })
    return [...map.values()]
}

console.log(JSON.stringify("3") === JSON.stringify(3))


function sort(arr) {
    if (arr.length < 1) return arr
    let left = [];
    let right = [];
    let mIndex = Math.floor(arr.length / 2)
    let middle = arr.splice(mIndex, 1)[0]
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] < middle) {
            left.push(arr[i])
        } else {
            right.push(arr[i])
        }
    }
    return sort(left).concat([middle], sort(right))
}


console.log(unique(flat(arr)).sort((a, b) => a - b))

function compose(fns, params) {
    return fns.reduce((pre, fn) => {
        return fn(pre)
    }, params)
}

console.log(compose([flat, unique, sort], arr))